package StringTest;
/**
 * 6.3.	验证一个ip的格式是否正确给定一个字符串,
 * 判断一下ip是不是合法;返回值为true或者false;
 * @author AcerMr
 *
 */
public class WangZhi
{
	public static void main(String[] args)
	{
		/*StringBuilder str = new StringBuilder("192.168.1.1");*/
		String  str = "168.1.1";
		String Arr [] = str.split("\\.");
		String zhengque = ""; 
		if(Arr.length != 4) 
		{
			System.out.println("非法IP");	
		}else
		{
			for (int i = 0; i < Arr.length; i++)
			{
				String string = Arr[i];
				try
				{
					Integer test = Integer.valueOf(string);
					if(test<0||test>255)
					{
						zhengque = "错误";
						break;
					}else
					{
						zhengque = "正确";
					}
				} catch (Exception e)
				{
					zhengque = "错误";
					break;
				}
				
			}
			
		}
		System.out.println(zhengque);
/*		for (int i = 0; i < Arr.length; i++)
		{
			String string = Arr[i];
			System.out.println(string);
		}*/
	}
}
